
package com.rt.schedulenew.web;
import com.rt.schedulebase.dto.ExamApplyDto;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
import com.rt.schedulenew.utils.util.JsonUtil;
import com.rt.schedulenew.utils.global.ErrorCode;
import com.rt.schedulenew.utils.base.ConstantsUtil;
import com.rt.schedulenew.utils.global.CustomMessage;
import java.util.ArrayList;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
import com.rt.schedulenew.utils.global.JsonResultUtil;
import java.util.HashMap;
import com.rt.schedulenew.utils.global.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import com.rt.schedulebase.core.websocket.NettyPushServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping({ "/socket" })
public class SocketController
{
//    @Value("${rt.netty.port}")
    private String port;

    @Autowired
    private NettyPushServer nettyPushServer;
    
    @RequestMapping({ "/info" })
    public JsonResult info() {
        final Map<String, Object> map = new HashMap<String, Object>();
        map.put("ip", "127.0.0.1");
        map.put("port", this.port);
        return JsonResultUtil.success("成功", map);
    }
    
    @PostMapping({ "/push" })
    public JsonResult push(@RequestBody ExamApplyDto dto) {
        List<String> list = new ArrayList<String>();
        List<String> patientNames = dto.getPatientNames();
        if (patientNames != null) {
            list.addAll(patientNames);

            CustomMessage customMessage = new CustomMessage();
            customMessage.setType(ConstantsUtil.NettyMsgCode.YY_CALL.getCode());
            customMessage.setContent(JsonResultUtil.success(list));
            nettyPushServer.sendMessageToAllUsers(JsonUtil.toJson(customMessage));
        }
        return JsonResultUtil.success(list);
    }
}
